package com.zking.utils.廖全箐;

import com.zking.dao.EvaluateDao;
import com.zking.dao.FoodDao;
import com.zking.frame.Client;

import javax.swing.*;
import java.awt.*;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class Reply extends JDialog {
    //商铺分类，商铺名称，菜品名，菜品价格，菜品图片地址，商家图片地址，商家展示。
    private JLabel nameJLabel;
    private JTextArea relyJLabel;
    private JTextArea nameField;
    private JPanel jPanel;
    public Reply (JFrame owner, boolean modal,String title,String string,String time){
        super(owner,modal);
        // 设置名字
        setTitle(title);
        // 设置背景颜色
        getContentPane().setBackground(Color.white);
        // 设置窗口大小
        setSize(700, 800);
        // 取消布局
        setLayout(null);
        // 设置居中
        setLocationRelativeTo(null);

        jPanel = new JPanel();
        jPanel.setBounds(0,0,686,700);
        jPanel.setBackground(Color.white);
        jPanel.setLayout(null);
        add(jPanel);
        nameJLabel = new JLabel("客户评价:",JLabel.RIGHT);
        nameJLabel.setBounds(0,225,150,50);
        nameJLabel.setFont(new Font("黑体",Font.BOLD,25));
        jPanel.add(nameJLabel);
        nameField = new JTextArea(string);
        nameField .setLineWrap(true);
        nameField.setEditable(false);
        nameField.setBounds(160,100,450,300);
        nameField.setBackground(new Color(238,238,238));
        nameField.setFont(new Font("黑体",Font.BOLD,20));
        jPanel.add(nameField);

        JLabel nameJLabel1 = new JLabel("回复:",JLabel.RIGHT);
        nameJLabel1.setBounds(0,450,150,50);
        nameJLabel1.setFont(new Font("黑体",Font.BOLD,25));
        jPanel.add(nameJLabel1);
        relyJLabel = new JTextArea("评价只截取前一百");
        relyJLabel.setForeground(Color.lightGray);
        relyJLabel .setLineWrap(true);
        relyJLabel.setBounds(160,450,450,200);
        relyJLabel.setBackground(new Color(238,238,238));
        relyJLabel.setFont(new Font("黑体",Font.BOLD,20));
        jPanel.add( relyJLabel);
        relyJLabel.addFocusListener(new FocusListener() {
            @Override
            public void focusGained(FocusEvent focusEvent) {
                if(relyJLabel.getText().equals("评价只截取前一百")){
                    relyJLabel.setText("");
                    relyJLabel.setForeground(Color.black);
                }
            }

            @Override
            public void focusLost(FocusEvent focusEvent) {
                if(relyJLabel.getText().equals("")){
                    relyJLabel.setText("评价只截取前一百");
                    relyJLabel.setForeground(Color.lightGray);
                }else{
                    if (relyJLabel.getText().length()>100) {
                        relyJLabel.setText(relyJLabel.getText().substring(0, 101));
                    }
                }
            }
        });

        JLabel nameJLabel2 = new JLabel("提交回复",0);
        nameJLabel2.setBounds(250,660,150,40);
        nameJLabel2.setBorder(BorderFactory.createMatteBorder(1,1,1,1,new Color(97,175,248)));
        nameJLabel2.setBackground(new Color(238,238,238));
        nameJLabel2.setOpaque(true);
        nameJLabel2.setFont(new Font("黑体",Font.BOLD,25));
        jPanel.add(nameJLabel2);

        nameJLabel2.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                if (e.getClickCount()==1){
                    String nJ = string+"\n商家回复："+relyJLabel.getText();
                    EvaluateDao evaluateDao = new EvaluateDao();
                    evaluateDao.updateRely(nJ,time);
                    dispose();
                }
            }
        });
        // 设置窗口不可调节
        setResizable(false);
        // 设置窗口是否可见
        setVisible(true);
        // 设置窗口关闭模式
        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    }

}
